/**
 * Copyright (c) 2008, EffCode, www.effcode.com
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list 
 * of conditions and the following disclaimer. 
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials
 * provided with the distribution. 
 * Neither the name of the EffCode nor the names of its contributors may be used 
 * to endorse or promote products derived from this software without specific prior written 
 * permission. 
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 
 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package org.effdom;

import org.effdom.impl.DocumentImpl;
import org.effdom.io.DocumentReader;
import org.effdom.io.DocumentWriter;
import org.effdom.io.impl.DocParserImpl;

/**
 * The <code>DocumentFactory</code> is the entry point for creating
 * <code>Document</code> and document readers and writers.
 * 
 * @author <a href="mailto:mattias@effcode.com">Mattias Jonsson</a>
 * 
 * @see Document
 */
public class DocumentFactory {
    
    public enum CompressType {
        GZIP,
        NONE;
    }

    private DocumentFactory() {
    }

    /**
     * Creates and instance of the <code>DocumentFactory</code>.
     * 
     * @return an instance of the <code>DocumentFactory</code>
     */
    public static DocumentFactory createInstance() {
        return new DocumentFactory();
    }

    /**
     * Creates an empty <code>Document.</code>
     * 
     * @return the default <code>Document</code> implementation
     */
    public Document createDocument() {
        return new DocumentImpl();
    }

    /**
     * Creates an empty <code>Document</code> of the specified version.
     * 
     * @param version the wanted <code>Document</code>
     * @return the <code>Document</code>
     * @throws UnsupportedOperationException if the version isn't supported
     */
    public Document createDocument(byte version) throws UnsupportedOperationException {
        switch (version) {
        case DocParserImpl.VERSION:
            return new DocumentImpl();
        default:
            throw new UnsupportedOperationException("Only supports version: " + DocParserImpl.VERSION);
        }
    }

    /**
     * Creates a <code>DocumentReader</code>
     * @return
     * @throws UnsupportedOperationException
     */
    public DocumentReader createDocumentReader() throws UnsupportedOperationException {
        return new DocParserImpl(CompressType.NONE);
    }

    public DocumentReader createDocumentReader(CompressType compressType) throws UnsupportedOperationException {
        return new DocParserImpl(compressType);
    }

    public DocumentWriter createDocumentWriter() throws UnsupportedOperationException {
        return new DocParserImpl(CompressType.NONE);
    }

    public DocumentWriter createDocumentWriter(CompressType compressType) throws UnsupportedOperationException {
        return new DocParserImpl(compressType);
    }
}
